﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Diagnostics;
using Microsoft.Search.Interop;

using System.IO;

namespace Fif.wss
{
    public static class Manager
    {
        public static void AddToIndex(string folder)
        {
            Validate(folder);

            try
            {
                var manager = new CSearchManager();
                var catalogManager = manager.GetCatalog("SystemIndex");
                var csm = catalogManager.GetCrawlScopeManager();
                if (!Convert.ToBoolean(csm.IncludedInCrawlScope(folder)))
                {                 
                    csm.AddUserScopeRule(folder, Convert.ToInt32(true), Convert.ToInt32(true), 0);
                    csm.SaveAll();
                }
            }
            catch(Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }            
        }

        private static void Validate(string path)
        {
            if (!Directory.Exists(path))
            {
                throw new ArgumentException("Path does not exists", path);
            }
        }
    }
}
